import request from '@/utils/request'

/**
 * API 接口统一管理
 * 所有的接口请求都在这里定义
 */

// ==================== 用户认证相关 ====================

/**
 * 用户注册
 */
export const register = (data) => {
  return request({
    url: '/api/auth/register',
    method: 'post',
    data
  })
}

/**
 * 用户登录
 */
export const login = (data) => {
  return request({
    url: '/api/auth/login',
    method: 'post',
    data
  })
}

/**
 * 获取当前用户信息
 */
export const getUserInfo = () => {
  return request({
    url: '/api/auth/user-info',
    method: 'get'
  })
}

/**
 * 发送密码找回邮件
 */
export const sendResetPasswordEmail = (email) => {
  return request({
    url: '/api/auth/send-reset-password-email',
    method: 'post',
    params: { email }
  })
}

/**
 * 重置密码
 */
export const resetPassword = (data) => {
  return request({
    url: '/api/auth/reset-password',
    method: 'post',
    data
  })
}

// ==================== 情侣关系相关 ====================

/**
 * 创建情侣关系（生成邀请码）
 */
export const createCouple = (data) => {
  return request({
    url: '/api/couple/create',
    method: 'post',
    data
  })
}

/**
 * 加入情侣关系（通过邀请码）
 */
export const joinCouple = (inviteCode) => {
  return request({
    url: '/api/couple/join',
    method: 'post',
    data: { inviteCode }
  })
}

/**
 * 获取情侣关系信息
 */
export const getCoupleInfo = () => {
  return request({
    url: '/api/couple/info',
    method: 'get'
  })
}

// ==================== 账单相关 ====================

/**
 * 上传账单截图
 */
export const uploadBillImage = (file) => {
  const formData = new FormData()
  formData.append('file', file)
  return request({
    url: '/api/upload/bill-image',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

/**
 * 创建账单
 */
export const createBill = (data) => {
  return request({
    url: '/api/bill/create',
    method: 'post',
    data
  })
}

/**
 * 获取账单列表（分页）
 */
export const getBillList = (params) => {
  return request({
    url: '/api/bill/list',
    method: 'get',
    params
  })
}

/**
 * 获取账单详情
 */
export const getBillDetail = (billId) => {
  return request({
    url: `/api/bill/${billId}`,
    method: 'get'
  })
}

/**
 * 获取待审批的账单列表
 */
export const getPendingBills = () => {
  return request({
    url: '/api/bill/pending',
    method: 'get'
  })
}

/**
 * 审批账单（同意/拒绝）
 */
export const approveBill = (data) => {
  return request({
    url: '/api/bill/approve',
    method: 'post',
    data
  })
}

/**
 * 更新账单
 */
export const updateBill = (billId, data) => {
  return request({
    url: `/api/bill/update/${billId}`,
    method: 'put',
    data
  })
}

/**
 * 删除账单
 */
export const deleteBill = (billId) => {
  return request({
    url: `/api/bill/delete/${billId}`,
    method: 'delete'
  })
}

/**
 * 获取账单统计数据（按年/月/日）
 */
export const getBillStatistics = (params) => {
  return request({
    url: '/api/bill/statistics',
    method: 'get',
    params
  })
}

// ==================== 余额相关 ====================

/**
 * 设置初始余额
 */
export const setBalance = (data) => {
  return request({
    url: '/api/balance/set',
    method: 'post',
    data
  })
}

/**
 * 确认对方的余额设置
 */
export const confirmPartnerBalance = (partnerUserId) => {
  return request({
    url: `/api/balance/confirm/${partnerUserId}`,
    method: 'post'
  })
}

/**
 * 获取双方余额信息
 */
export const getBalanceInfo = () => {
  return request({
    url: '/api/balance/info',
    method: 'get'
  })
}

/**
 * 获取余额变更历史列表
 */
export const getBalanceChangeLogList = (params) => {
  return request({
    url: '/api/balance-change-log/list',
    method: 'get',
    params
  })
}

/**
 * 获取余额变更统计信息
 */
export const getBalanceChangeStatistics = () => {
  return request({
    url: '/api/balance-change-log/statistics',
    method: 'get'
  })
}

/**
 * 发起余额修改请求
 */
export const createBalanceRequest = (data) => {
  return request({
    url: '/api/balance-request/create',
    method: 'post',
    data
  })
}

/**
 * 审批余额修改请求
 */
export const approveBalanceRequest = (data) => {
  return request({
    url: '/api/balance-request/approve',
    method: 'post',
    data
  })
}

/**
 * 获取待我审批的余额修改请求列表
 */
export const getPendingBalanceRequests = () => {
  return request({
    url: '/api/balance-request/pending',
    method: 'get'
  })
}

/**
 * 获取我发起的余额修改请求列表
 */
export const getMyBalanceRequests = () => {
  return request({
    url: '/api/balance-request/my',
    method: 'get'
  })
}

// ==================== 恋爱金库相关 ====================

/**
 * 获取金库信息
 */
export const getTreasuryInfo = () => {
  return request({
    url: '/api/treasury/info',
    method: 'get'
  })
}

/**
 * 创建金库交易（存入/取出）
 */
export const createTreasuryTransaction = (data) => {
  return request({
    url: '/api/treasury/transaction',
    method: 'post',
    data
  })
}

/**
 * 获取金库交易记录列表（分页）
 */
export const getTreasuryTransactions = (params) => {
  return request({
    url: '/api/treasury/transactions',
    method: 'get',
    params
  })
}

// ==================== 日记相关 ====================

/**
 * 创建日记
 */
export const createDiary = (data) => {
  return request({
    url: '/api/diary/create',
    method: 'post',
    data
  })
}

/**
 * 获取日记列表
 */
export const getDiaryList = (params) => {
  return request({
    url: '/api/diary/list',
    method: 'get',
    params
  })
}

/**
 * 获取日记详情
 */
export const getDiaryDetail = (id) => {
  return request({
    url: `/api/diary/${id}`,
    method: 'get'
  })
}

/**
 * 更新日记
 */
export const updateDiary = (id, data) => {
  return request({
    url: `/api/diary/${id}`,
    method: 'put',
    data
  })
}

/**
 * 删除日记
 */
export const deleteDiary = (id) => {
  return request({
    url: `/api/diary/${id}`,
    method: 'delete'
  })
}

// ==================== 小纸条相关 ====================

/**
 * 发送小纸条
 */
export const sendLoveNote = (data) => {
  return request({
    url: '/api/note/send',
    method: 'post',
    data
  })
}

/**
 * 获取小纸条列表
 */
export const getLoveNoteList = (params) => {
  return request({
    url: '/api/note/list',
    method: 'get',
    params
  })
}

/**
 * 标记小纸条为已读
 */
export const markLoveNoteAsRead = (id) => {
  return request({
    url: `/api/note/${id}/read`,
    method: 'post'
  })
}

/**
 * 删除小纸条
 */
export const deleteLoveNote = (id) => {
  return request({
    url: `/api/note/${id}`,
    method: 'delete'
  })
}

/**
 * 获取未读小纸条数量
 */
export const getUnreadLoveNoteCount = () => {
  return request({
    url: '/api/note/unread-count',
    method: 'get'
  })
}

/**
 * 批量删除小纸条
 */
export const batchDeleteLoveNotes = (ids) => {
  return request({
    url: '/api/note/batch-delete',
    method: 'post',
    data: { ids }
  })
}

/**
 * 一键删除所有小纸条
 */
export const deleteAllLoveNotes = () => {
  return request({
    url: '/api/note/delete-all',
    method: 'delete'
  })
}

// ==================== 纪念日相关 ====================

/**
 * 创建纪念日
 */
export const createAnniversary = (data) => {
  return request({
    url: '/api/anniversary/create',
    method: 'post',
    data
  })
}

/**
 * 获取纪念日列表
 */
export const getAnniversaryList = () => {
  return request({
    url: '/api/anniversary/list',
    method: 'get'
  })
}

/**
 * 更新纪念日
 */
export const updateAnniversary = (id, data) => {
  return request({
    url: `/api/anniversary/${id}`,
    method: 'put',
    data
  })
}

/**
 * 删除纪念日
 */
export const deleteAnniversary = (id) => {
  return request({
    url: `/api/anniversary/${id}`,
    method: 'delete'
  })
}

/**
 * 获取即将到来的纪念日（7天内）
 */
export const getUpcomingAnniversaries = () => {
  return request({
    url: '/api/anniversary/upcoming',
    method: 'get'
  })
}

// ==================== 成就相关 ====================

/**
 * 获取用户成就列表
 */
export const getUserAchievements = () => {
  return request({
    url: '/api/achievement/list',
    method: 'get'
  })
}

// ==================== 文件上传 ====================

/**
 * 上传文件（头像、图片等）
 * @param {FormData} formData - 包含文件的 FormData 对象
 */
export const uploadFile = (formData) => {
  return request({
    url: '/api/upload',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

// ==================== 通知相关 ====================

/**
 * 获取通知列表（分页）
 */
export const getNotificationList = (params) => {
  return request({
    url: '/api/notification/list',
    method: 'get',
    params
  })
}

/**
 * 获取未读通知数量
 */
export const getUnreadCount = () => {
  return request({
    url: '/api/notification/unread-count',
    method: 'get'
  })
}

/**
 * 标记通知为已读
 */
export const markNotificationAsRead = (id) => {
  return request({
    url: `/api/notification/mark-read/${id}`,
    method: 'post'
  })
}

/**
 * 标记所有通知为已读
 */
export const markAllNotificationsAsRead = () => {
  return request({
    url: '/api/notification/mark-all-read',
    method: 'post'
  })
}

/**
 * 删除通知
 */
export const deleteNotification = (id) => {
  return request({
    url: `/api/notification/${id}`,
    method: 'delete'
  })
}

/**
 * 批量删除通知
 */
export const batchDeleteNotifications = (ids) => {
  return request({
    url: '/api/notification/batch-delete',
    method: 'post',
    data: { ids }
  })
}

/**
 * 一键删除所有通知
 */
export const deleteAllNotifications = () => {
  return request({
    url: '/api/notification/delete-all',
    method: 'delete'
  })
}

// ==================== 用户信息更新相关 ====================

/**
 * 更新用户信息
 */
export const updateUserInfo = (data) => {
  return request({
    url: '/api/user/update',
    method: 'put',
    data
  })
}

/**
 * 修改密码
 */
export const changePassword = (data) => {
  return request({
    url: '/api/user/change-password',
    method: 'post',
    data
  })
}
